/*=============================================================================

  AREA APPLICATION MODULE

  FILE: area.h
  
  DESCRIPTION

    Module for Application

  EXTERNALIZED FUNCTIONS

    
  Copyright (c) DaeSung Engineering Inc. All rights reserved.

=============================================================================*/
/*=============================================================================

                             EDIT HISTORY

  ---------  -------  -------------------------------------------------------
    when       who     what, where, why
  ---------  -------  -------------------------------------------------------
   05/26/05   pkim    Version E01.0

=============================================================================*/

/*=============================================================================
  HEADER INCLUSION
=============================================================================*/
#include <area_mod.h>

/*=============================================================================
  CONSTANT DEFINITION
=============================================================================*/

/*=============================================================================
  STRUCTURE DEFINITION
=============================================================================*/

/*=============================================================================
  LOCALIZED FUNCTION DEFINITION
=============================================================================*/

/*=============================================================================
  EXTERNALIZED FUNCTION IMPLEMENTATION
=============================================================================*/
mcxt area_alloc(ObjClient_s *c)
{
	area_s			*cxt;
	
	cxt = (area_s*)memCalloc(sizeof(*cxt));

	area_cfg_alloc(cxt);
	
	if(c)
	{
		cxt->c = (ObjClient_s*)memCalloc(sizeof(*c));
		memCopy(cxt->c, c, sizeof(*c));
	}
	
	return	(mcxt)cxt;
}

boolean area_free(mcxt app)
{
	area_s			*cxt = AREACXT(app);

	if(cxt == NULL)
		return	FALSE;

	if(cxt->c != NULL)
	{
		memFree(cxt->c);
		cxt->c = NULL;
	}
	area_cfg_free(cxt);
	
	memFree(cxt);
	
	return	TRUE;
}

boolean area_init(mcxt app)
{
	area_s	*cxt = AREACXT(app);
	
	if(cxt == NULL)
		return	FALSE;

	area_cfg_init(cxt);
	area_task_init(cxt);

	return	TRUE;
}

boolean area_close(mcxt app)
{
	area_s			*cxt = AREACXT(app);

	if(cxt == NULL)
		return	FALSE;
	
	if(cxt->img)
	{
		IMP_FREE(cxt->img);
		cxt->img = NULL;
	}

	area_cfg_close(cxt);
	area_task_close(cxt);
	
	return	TRUE;
}

boolean area_mode_set(mcxt app, int32 mode)
{
	area_s			*cxt = AREACXT(app);
	
	if(cxt == NULL)
		return	FALSE;

	if(cxt->mode == (dword)mode)
		return	TRUE;

	cxt->mode = mode;	

	return	TRUE;
}

int32 area_mode_get(mcxt app)
{
	area_s			*cxt = AREACXT(app);
	
	if(cxt == NULL)
		return	AREA_NONE_M;

	return	cxt->mode;
}

boolean area_rtui_set(mcxt app, int32 id, mcxt ui_cxt)
{
	area_s			*cxt = AREACXT(app);
	
	if(cxt == NULL)
		return	FALSE;

	if(!RANGE_IN(id, AREA_VMAIN_RTUI, (AREA_MAX_RTUI-1)))
	{
		return	FALSE;
	}
	cxt->rtui[id] = ui_cxt;
	
	return	TRUE;
}

boolean area_cfg_set(mcxt app, area_cfg_s *cfg)
{
	area_s			*cxt = AREACXT(app);
	area_cfg_s		*c;
	
	if(cxt == NULL)
		return	FALSE;

	c = CFGMOD(app);
	memCopy(c, cfg, sizeof(*cfg));
	
	return	TRUE;
}

boolean area_cfg_get(mcxt app, area_cfg_s *cfg)
{
	area_s			*cxt = AREACXT(app);
	area_cfg_s		*c;
	
	if(cxt == NULL)
		return	FALSE;

	c = CFGMOD(app);
	memCopy(cfg, c, sizeof(*c));

	return	TRUE;
}

/*--- END OF area.cpp ---*/
